﻿<?php
defined('_JEXEC') or die('Restricted access'); 
 
jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');

?>
<script type="text/javascript">
	//<![CDATA[
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save') {
			if (document.adminForm.name.value == '') {
				alert( 'Must have outlet name !' );
				document.adminForm.name.focus();
				return false;
			}
			if(jQuery("#coutlets").val()>0){
				jQuery("#warning").html("Please choose a different outlet code");
				return false;
			}
			if (document.adminForm.code.value == '') {
				alert( 'Must have code !' );
				document.adminForm.code.focus();
				return false;
			}

			submitform( pressbutton );
		}
	}

	var sectionprojects = new Array;
	<?php
		foreach ($this->lists['projectToClub'] as $k=>$item) {
			echo "sectionprojects[".$k."] = new Array( '$item->pid','".addslashes( $item->code )."','".addslashes( $item->name )."' );\n\t\t";
		}
	?>

	function changeClubs( listname, source, key, orig_key, orig_val ) {
		var list = eval( 'document.adminForm.' + listname );

		// empty the list
		for (i in list.options.length) {
			list.options[i] = null;
		}

		var i = 0;
		var j = 0;
		for (x in source) {
			if (source[x][0] == key) {
				opt = new Option();
				opt.value = source[x][1];

				opt.text = source[x][2];

				if ((orig_key == key && orig_val == opt.value) || i == 0) {
					opt.selected = true;
					j = opt.value;
				}
				list.options[i++] = opt;
			}
		}
		if(i == 0){
			opt = new Option();
			opt.value = 0;
			opt.text = '- Select Clubs -';
			opt.selected = true;
			list.options[i++] = opt;
		}

		list.length = i;
	}
	
function checkOutletCode(code){
	var code = code;
	jQuery("document").ready(function(){
			
			
		
			if(code == '') {jQuery("#warning").css('color','red').html("Warning: Please enter Code Outlet");}
			
			jQuery.ajax({
			
				url: "index.php?option=com_wrd&controller=outlets&task=checkOutletCode",
				type: "POST",
				data: 'code='+code,
				success: function (res) {
					
					if(res>0){jQuery("#warning").css('color','red').html("Warning: Outlet Code exist");}
					
					else if((code != '')&&(res==0)){
					
						jQuery("#warning").css('color','#35c00f').html("OK. Outlet Code maybe use");
						
					}
					
					jQuery("#coutlets").val(res);
				}		
			});
	});
	
}
</script>

<form id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd&controller=outlets")?>" method="post" name="adminForm" >
	<div class="row-fluid">
	    <fieldset class="adminform">
	    	<legend><?php echo JText::_('Details')?></legend>
			<table class="table table-striped adminlist">
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Projects')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['projects']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Clubs')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['clubs']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Outlet Name')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->name; ?>" id="name" name="name" class="name"/> *
					</td>
				</tr>
				
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Outlet Name Vietnamese')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->name_vi; ?>" id="name_vi" name="name_vi" class="name"/> *
					</td>
				</tr>
				
				<tr>
					<td class="key">
						<label title="Mã Outlets tối đa 3 ký tự"  for="title"><?php echo JText::_('Code')?>:</label>
					</td>
					<td colspan="2">
						<input onkeyup="return checkOutletCode(this.value)" type="text" title="type" maxlength="3" size="50" value="<?php echo $this->data->code; ?>" id="code" name="code" class="code"/> *
						<div style="font-size: 13px;float: right;font-weight: bold;height: 20px;padding-top: 5px;width: 280px;" id="warning"></div>
					</td>
					
				</tr>
				<tr>
					<td class="key" valign='top'>
						<label for="title"><?php echo JText::_('Descriptions')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['des']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Address (English)')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" maxlength="50" size="50" value="<?php echo $this->data->address; ?>" id="address" name="address" class="address"/>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Address (Vietnamese)')?>:</label>
					</td>
					<td colspan="2">
						<input type="text"maxlength="50" size="50" value="<?php echo $this->data->address_vi; ?>" id="address_vi" name="address_vi" class="address_vi"/>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Publish')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['published']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Show in config point')?>:</label>
					</td>
					<td colspan="2">
						<input type="checkbox" name="published_cpoint" <?php echo ($this->lists['published_cpoint'] == 1 ? "checked" : "");?> />
					</td>
				</tr>
            </table>
		</fieldset>
	</div>
	<input type="hidden" id="coutlets" value="0" />
	<input type="hidden" name="created_id" value="<?php echo $this->user->id;?>" />
	<input type="hidden" name="flag_id" value="<?php echo $this->lists['flag_id'] ; ?>" />
	<input type="hidden" name="controller" value="outlets" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="id" value="<?php echo (int)$this->data->id; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>
